package com.gaoxiang.demo.config;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * TODO
 *
 * @author gaoxiang
 * @date 2020/9/109:33
 */

@Component
public class EsConfig {
    @Bean
    public TransportClient elClient() throws Exception {
        Settings settings = Settings.builder()
                .put("cluster.name", "gaoxiang-application").put("client.transport.sniff", true).build();
        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
        return client;
    }

}

